<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .father {
      width: 200px;
      height: 200px;
      background-color: red;
    }
    .son {
      width: 100px;
      height: 100px;
      background-color: blue;
    }
    .son-son {
      width: 50px;
      height: 50px;
      background-color: green;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="son">
      <div class="son-son">
        
      </div>
    </div>
  </div>
  <script>
    const father = document.querySelector('.father')
    const son = document.querySelector('.son')
    const sonSon = document.querySelector('.son-son')
    // DOM.addEventListener(事件类型,事件处理函数,是否使用捕获机制)
    // true: 捕获阶段,爷爷->爸爸->儿子->孙子
    // document.addEventListener('click', function () {
    //   alert('我是爷爷')
    // }, true)
    // father.addEventListener('click', function () {
    //   alert('我是爸爸')
    // }, true)
    // son.addEventListener('click', function () {
    //   alert('我是儿子')
    // }, true)
    // sonSon.addEventListener('click', function () {
    //   alert('我是孙子')
    // }, true)


    // false: 冒泡阶段,孙子->儿子->爸爸->爷爷
    document.addEventListener('click', function () {
      alert('我是爷爷')
    }, false)
    father.addEventListener('click', function () {
      alert('我是爸爸')
    })
    son.addEventListener('click', function () {
      alert('我是儿子')
    })
    sonSon.addEventListener('click', function (event) {
      alert('我是孙子')
      // 阻止冒泡
      event.stopPropagation()
    })
  </script>
</body>
</html>